<template>
    <div>
         <list title="编辑联系人"/>
         <div class="lr">
             <van-address-edit
                :area-list="areaList"
                show-postal
                show-delete
                :address-info = "contact"
                show-set-default
                show-search-result
                :search-result="searchResult"
                :area-columns-placeholder="['请选择', '请选择', '请选择']"
                @save="onSave"
                @delete="onDelete"
                @change-detail="onChangeDetail"
                />
         </div>
    </div>
</template>

<script>
import list from '@views/Home/component/ItemListHead'
import { areaList } from '@vant/area-data'
import { Toast } from 'vant'
export default {
  data () {
    return {
      areaList,
      contact: {} // 当前编辑的这个联系人
    }
  },
  created () {
    this.fetchContact()
  },
  methods: {
    ondelete () {
      alert(1)
    },
    fetchContact () {
      this.contact = this.$store.state.contact.contacts[parseInt(this.$route.query.index)]
    },
    onSave (contact) {
      console.log(contact)
      this.$store.commit('contact/update_contact', {
        index: parseInt(this.$route.query.index),
        contact
      })
      Toast('修改成功')
      this.$router.replace('/contactLists')
    }
  },
  components: { list }
}
</script>
<style lang='scss'>
.lr{
    margin-top: 46px;
}
</style>
